<template>
  <div >
    <div>
      <el-button type="primary" icon="el-icon-search" @click="onSearchClick()">搜索</el-button>
      <el-input style="width: 30%"
                placeholder="请输入内容(UID/昵称)"
                v-model="inputDesc">
        <i slot="prefix" class="el-input__icon el-icon-search"></i>
      </el-input>
      <el-divider><i class="el-icon-zoom-in"></i></el-divider>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%"
      height="950">
      <el-table-column
        prop="userUid"
        label="对象UID">
      </el-table-column>
      <el-table-column
        prop="userName"
        label="对象昵称">
      </el-table-column>
      <el-table-column
        prop="adminUid"
        label="管理员UID">
      </el-table-column>
      <el-table-column
        prop="adminName"
        label="管理员">
      </el-table-column>
      <el-table-column
        prop="adminAddr"
        label="管理员IP">
      </el-table-column>
      <el-table-column
        prop="operation"
        label="操作">
      </el-table-column>
      <el-table-column
        prop="operationTime"
        label="操作时间">
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      v-show="allSize > 30"
      style="margin-top: 20px"
      background
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :current-page.sync="currentPage"
      :total="allSize"
      :page-size="pageSize">
    </el-pagination>
  </div>

</template>

<script>
  import axios from 'axios'
  const pageSizeConst = 30;
  export default {
    created() {
      this.initCreate();
    },
    methods: {
      handleCurrentChange: function(currentPage){
        this.currentPage = currentPage;
        if(this.tag === 1){
          this.initCreate()
        }else {
          this.onSearchClick();
        }

      },
      initCreate(){
        this.allFind();
      },
      allFind(){
        axios.get("/getgm",{
          params:{
            pageSize: pageSizeConst,
            currentPage: this.currentPage,
          }
        }).then(resp => {
          if(resp.data.result){
            this.tableData = resp.data.msg.data
            this.allSize = resp.data.msg.count
          }
        })
      },
      onSearchClick() {
        if(this.inputDesc == null || this.inputDesc === ""){
          this.tag = 1;
          this.allFind();
          return;
        }
        this.tag = 2;
        axios.get("/searchgm",{
          params:{
            pageSize: pageSizeConst,
            currentPage: this.currentPage,
            uid:this.inputDesc
          }
        }).then(resp => {
          if(resp.data.result){
            this.tableData = resp.data.msg.data
            this.allSize = resp.data.msg.count
          }
        })
      },
    },
    data() {
      return {
        tableData: [],
        inputDesc: '',
        currentPage: 1,
        pageSize: pageSizeConst,
        allSize: 0,
        tag:1
      }
    }
  }
</script>

<style scoped>

</style>

